package com.tiza.xiaoyoubao.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.squareup.picasso.Picasso;
import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.Constants;
import com.tiza.xiaoyoubao.entity.BrowseCompleteInfo;
import com.tiza.xiaoyoubao.entity.BrowseConfirmInfo;
import com.tiza.xiaoyoubao.entity.BrowseJDTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.BrowseMGJTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.BrowseMLSTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.BrowseOperateInfo;
import com.tiza.xiaoyoubao.entity.BrowseTMTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.BrowseTaskOrderInfo;
import com.tiza.xiaoyoubao.entity.TaskOrderInfo;
import com.tiza.xiaoyoubao.net.ApiHttpClient;
import com.tiza.xiaoyoubao.utils.DateUtils;

import butterknife.BindView;

/**
 * Created by mapple on 17/4/14.
 * 手机浏览任务详情2
 */

public class BrowseMpTaskDetail2Fragment extends BaseFragment {
    @BindView(R.id.tv_shopName)
    TextView tv_shopName;
    @BindView(R.id.tv_shopDescribe)
    TextView tv_shopDescribe;
    @BindView(R.id.tv_keyWord)
    TextView tv_keyWord;
    @BindView(R.id.tv_showPrice)
    TextView tv_showPrice;
    @BindView(R.id.tv_taskType)
    TextView tv_taskType;
    @BindView(R.id.tv_receiving)
    TextView tv_receiving;
    @BindView(R.id.tv_location)
    TextView tv_location;
    @BindView(R.id.iv_image)
    ImageView iv_image;
    @BindView(R.id.tv_city)
    TextView tv_city;
    @BindView(R.id.tv_priceInterval)
    TextView tv_priceInterval;
    @BindView(R.id.tv_additionalRequest)
    TextView tv_additionalRequest;

    private BrowseTaskOrderInfo browseTaskOrderInfo;
    private BrowseJDTaskOrderInfo browseJDTaskOrderInfo;
    private BrowseMGJTaskOrderInfo browseMGJTaskOrderInfo;
    private BrowseMLSTaskOrderInfo browseMLSTaskOrderInfo;
    private BrowseTMTaskOrderInfo browseTMTaskOrderInfo;
    private BrowseCompleteInfo browseCompleteInfo;
    private BrowseOperateInfo browseOperateInfo;
    private BrowseConfirmInfo browseConfirmInfo;
    Bundle args;
    private String state;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        args = getArguments();
        state = args.getString("state");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_browse_mp_task_detail2;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        switch (state) {
            case "browseOperate":
                BrowseOperate();
                break;
            case "confirm":
                BrowseConfirm();
                break;
            case "browseComplate":
                BrowseComplate();
                break;
            case "browseMgj":
                BrowseMGJ();
                break;
            case "browseMls":
                BrowseMLS();
                break;
            case "browseJd":
                BrowseJd();
                break;
            case "browseTm":
                BrowseTm();
                break;
            case "browseTb":
                BrowseTaoBao();
                break;
            default:
                break;
        }
    }

    public void BrowseTaoBao() {
        browseTaskOrderInfo = (BrowseTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(browseTaskOrderInfo.getShopName()
                .replaceFirst(browseTaskOrderInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseTaskOrderInfo.getTitle()
                    .substring(15,
                            browseTaskOrderInfo.getTitle()
                                    .length()
                    ));
        }
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_showPrice.setText(browseTaskOrderInfo.getMobilePrice());
        tv_taskType.setText(browseTaskOrderInfo.getTypeName());
        tv_keyWord.setText(browseTaskOrderInfo.getKeywords());
        tv_receiving.setText(browseTaskOrderInfo.getReceiving());
        tv_city.setText(browseTaskOrderInfo.getCity());
        if (browseTaskOrderInfo.getLocation().equals("xiaoliang")) {
            tv_location.setText("销量");
        } else if (browseTaskOrderInfo.getLocation().equals("zhitongche")) {
            tv_location.setText("直通车");
        } else if (browseTaskOrderInfo.getLocation().equals("zonghe")) {
            tv_location.setText("综合");
        }
        tv_priceInterval.setText(browseTaskOrderInfo.getPriceSection());
        if (browseTaskOrderInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseTaskOrderInfo.getRemarks());
        }
    }

    public void BrowseJd() {
        browseJDTaskOrderInfo = (BrowseJDTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(browseJDTaskOrderInfo.getShopName()
                .replaceFirst(browseJDTaskOrderInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseJDTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseJDTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseJDTaskOrderInfo.getTitle()
                    .substring(15,
                            browseJDTaskOrderInfo.getTitle()
                                    .length()
                    ));
        }
       /* Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseJDTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);*/
        tv_showPrice.setText(browseJDTaskOrderInfo.getMobilePrice());
        tv_taskType.setText(browseJDTaskOrderInfo.getTypeName());
        tv_keyWord.setText(browseJDTaskOrderInfo.getKeywords());
        tv_receiving.setText(browseJDTaskOrderInfo.getReceiving());
        tv_location.setText(browseJDTaskOrderInfo.getLocation());
        tv_city.setText(browseJDTaskOrderInfo.getCity());
        if (browseJDTaskOrderInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseJDTaskOrderInfo.getRemarks());
        }
    }

    public void BrowseTm() {
        browseTMTaskOrderInfo = (BrowseTMTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(browseTMTaskOrderInfo.getShopName()
                .replaceFirst(browseTMTaskOrderInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseTMTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseTMTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseTMTaskOrderInfo.getTitle()
                    .substring(15,
                            browseTMTaskOrderInfo.getTitle()
                                    .length()
                    ));
        }
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseTMTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_showPrice.setText(browseTMTaskOrderInfo.getMobilePrice());
        tv_taskType.setText(browseTMTaskOrderInfo.getTypeName());
        tv_keyWord.setText(browseTMTaskOrderInfo.getKeywords());
        tv_receiving.setText(browseTMTaskOrderInfo.getReceiving());
        if (browseTaskOrderInfo.getLocation().equals("xiaoliang")) {
            tv_location.setText("销量");
        } else if (browseTaskOrderInfo.getLocation().equals("zhitongche")) {
            tv_location.setText("直通车");
        } else if (browseTaskOrderInfo.getLocation().equals("zonghe")) {
            tv_location.setText("综合");
        }
        tv_city.setText(browseTMTaskOrderInfo.getCity());
        tv_priceInterval.setText(browseTaskOrderInfo.getPriceSection());
        if (browseTMTaskOrderInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseTMTaskOrderInfo.getRemarks());
        }
    }

    public void BrowseMLS() {
        browseMLSTaskOrderInfo = (BrowseMLSTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(browseMLSTaskOrderInfo.getShopName()
                .replaceFirst(browseMLSTaskOrderInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseMLSTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseMLSTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseMLSTaskOrderInfo.getTitle()
                    .substring(15,
                            browseMLSTaskOrderInfo.getTitle()
                                    .length()
                    ));
        }
       /* Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseMLSTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);*/
        tv_showPrice.setText(browseMLSTaskOrderInfo.getMobilePrice());
        tv_taskType.setText(browseMLSTaskOrderInfo.getTypeName());
        tv_keyWord.setText(browseMLSTaskOrderInfo.getKeywords());
        tv_receiving.setText(browseMLSTaskOrderInfo.getReceiving());
        tv_location.setText(browseMLSTaskOrderInfo.getLocation());
        tv_city.setText(browseMLSTaskOrderInfo.getCity());
        tv_priceInterval.setText(browseMLSTaskOrderInfo.getPrice());
        if (browseMLSTaskOrderInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseMLSTaskOrderInfo.getRemarks());
        }
    }

    public void BrowseMGJ() {
        browseMGJTaskOrderInfo = (BrowseMGJTaskOrderInfo) args.getSerializable("info");
        tv_shopName.setText(browseMGJTaskOrderInfo.getShopName()
                .replaceFirst(browseMGJTaskOrderInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseMGJTaskOrderInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseMGJTaskOrderInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseMGJTaskOrderInfo.getTitle()
                    .substring(15,
                            browseMGJTaskOrderInfo.getTitle()
                                    .length()
                    ));
        }
      /*  Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseMGJTaskOrderInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);*/
        tv_showPrice.setText(browseMGJTaskOrderInfo.getMobilePrice());
        tv_taskType.setText(browseMGJTaskOrderInfo.getTypeName());
        tv_keyWord.setText(browseMGJTaskOrderInfo.getKeywords());
        tv_receiving.setText(browseMGJTaskOrderInfo.getReceiving());
        tv_location.setText(browseMGJTaskOrderInfo.getLocation());
        tv_city.setText(browseMGJTaskOrderInfo.getCity());
        tv_priceInterval.setText(browseMGJTaskOrderInfo.getPrice());
        if (browseMGJTaskOrderInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseMGJTaskOrderInfo.getRemarks());
        }
    }

    public void BrowseComplate() {
        browseCompleteInfo = (BrowseCompleteInfo) args.getSerializable("info");
        tv_shopName.setText(browseCompleteInfo.getShopName()
                .replaceFirst(browseCompleteInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseCompleteInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseCompleteInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseCompleteInfo.getTitle()
                    .substring(15,
                            browseCompleteInfo.getTitle()
                                    .length()
                    ));
        }
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseCompleteInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_showPrice.setText(browseCompleteInfo.getMobilePrice());
        tv_taskType.setText(browseCompleteInfo.getTypeName());
        tv_keyWord.setText(browseCompleteInfo.getKeywords());
        tv_city.setText(browseCompleteInfo.getCity());
        tv_receiving.setText(browseCompleteInfo.getReceiving());
        if (browseCompleteInfo.getLocation().equals("xiaoliang")) {
            tv_location.setText("销量");
        } else if (browseCompleteInfo.getLocation().equals("zhitongche")) {
            tv_location.setText("直通车");
        } else if (browseCompleteInfo.getLocation().equals("zonghe")) {
            tv_location.setText("综合");
        }
        tv_priceInterval.setText(browseCompleteInfo.getPriceSection());
        if (browseCompleteInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseCompleteInfo.getRemarks());
        }
    }

    public void BrowseOperate() {
        browseOperateInfo = (BrowseOperateInfo) args.getSerializable("info");
        tv_shopName.setText(browseOperateInfo.getShopName()
                .replaceFirst(browseOperateInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseOperateInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseOperateInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseOperateInfo.getTitle()
                    .substring(15,
                            browseOperateInfo.getTitle()
                                    .length()
                    ));
        }
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseOperateInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_showPrice.setText(browseOperateInfo.getMobilePrice());
        tv_taskType.setText(browseOperateInfo.getTypeName());
        tv_keyWord.setText(browseOperateInfo.getKeywords());
        tv_city.setText(browseOperateInfo.getCity());
        tv_receiving.setText(browseOperateInfo.getReceiving());
        if (browseOperateInfo.getLocation().equals("xiaoliang")) {
            tv_location.setText("销量");
        } else if (browseOperateInfo.getLocation().equals("zhitongche")) {
            tv_location.setText("直通车");
        } else if (browseOperateInfo.getLocation().equals("zonghe")) {
            tv_location.setText("综合");
        }
        tv_priceInterval.setText(browseOperateInfo.getPriceSection());
        if (browseOperateInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseOperateInfo.getRemarks());
        }
    }

    public void BrowseConfirm() {
        browseConfirmInfo = (BrowseConfirmInfo) args.getSerializable("info");
        tv_shopName.setText(browseConfirmInfo.getShopName()
                .replaceFirst(browseConfirmInfo.getShopName().substring(0, 1),
                        "*"
                ));
        if (browseConfirmInfo.getTitle().length() <= 15) {
            tv_shopDescribe.setText(browseConfirmInfo.getTitle());
        } else {
            tv_shopDescribe.setText("***" + browseConfirmInfo.getTitle()
                    .substring(15,
                            browseConfirmInfo.getTitle()
                                    .length()
                    ));
        }
        Picasso.with(getActivity())
                .load(ApiHttpClient.URL2 + browseConfirmInfo.getImages())
                .placeholder(R.mipmap.rwcx_jiazaizhong)
                .error(R.mipmap.rwcx_jiazaizhong)
                .into(iv_image);
        tv_showPrice.setText(browseConfirmInfo.getMobilePrice());
        tv_taskType.setText(browseConfirmInfo.getTypeName());
        tv_keyWord.setText(browseConfirmInfo.getKeywords());
        tv_receiving.setText(browseConfirmInfo.getReceiving());
        tv_city.setText(browseConfirmInfo.getCity());
        if (browseConfirmInfo.getLocation().equals("xiaoliang")) {
            tv_location.setText("销量");
        } else if (browseConfirmInfo.getLocation().equals("zhitongche")) {
            tv_location.setText("直通车");
        } else if (browseConfirmInfo.getLocation().equals("zonghe")) {
            tv_location.setText("综合");
        }
        tv_priceInterval.setText(browseConfirmInfo.getPriceSection());
        if (browseConfirmInfo.getRemarks().equals(" ")) {
            tv_additionalRequest.setText("商家要求:此商家无其他要求");
        } else {
            tv_additionalRequest.setText("商家要求:" + browseConfirmInfo.getRemarks());
        }
    }

}
